package com.aifast.core.db.queue;

import cn.hutool.core.lang.Console;
import cn.hutool.extra.spring.SpringUtil;
import com.aifast.system.log.service.LogOperationService;
import redis.clients.jedis.JedisPubSub;

/**
 * @Author fujian
 * @since 2022/1/24 11:56
 */
public class AiSubPub extends JedisPubSub {

    private LogOperationService logOperationService = SpringUtil.getBean(LogOperationService.class);

    public static final String CHANNEL_LOG_OPERATION = "channel_log_operation";


    /**
     * 根据不同的channel频道message信息处理不同的业务
     * @param channel 频道
     * @param message 信息
     */
    @Override
    public void onMessage(String channel, String message) {
        switch (channel){
            case CHANNEL_LOG_OPERATION:
                logOperationService.consume(message);
                break;
            default:
                break;
        }

    }

    @Override
    public void onPMessage(String pattern, String channel, String message) {
        Console.log("频道 " + channel + " 收到一条消息：" + message + " ["+ pattern + "]");
    }

    @Override
    public void onSubscribe(String channel, int subscribedChannels) {
        Console.log("初始化订阅频道 " + channel + " " +subscribedChannels);
    }

    @Override
    public void onUnsubscribe(String channel, int subscribedChannels) {
        Console.log("取消订阅频道 " + channel + " " +subscribedChannels);
    }

    @Override
    public void onPUnsubscribe(String pattern, int subscribedChannels) {
        super.onPUnsubscribe(pattern, subscribedChannels);
    }

    @Override
    public void onPSubscribe(String pattern, int subscribedChannels) {
        super.onPSubscribe(pattern, subscribedChannels);
    }
}
